﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BKH.BLL;

namespace BKH.MyUserControl.UCHienThi
{
    public partial class ucThemBenhNhan : UserControl
    {
        String ID_Co;
        
        public ucThemBenhNhan()
        {
            
            InitializeComponent();
            showData();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            insertBenhNhan();
        }
        /// <summary>
        /// Hiển thị danh sách bệnh nhân
        /// </summary>
        void showData()
        {
            BenhNhanBUO bnbuo = new BenhNhanBUO();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = bnbuo.GetAll();
        }
        /// <summary>
        /// Thêm bệnh nhân
        /// </summary>
        void insertBenhNhan()
        {
            BenhNhanBUO bnbuo = new BenhNhanBUO();
            tbl_BenhNhan tbl = new tbl_BenhNhan();

            tbl.Address = txtAddress.Text;
            tbl.BHYT = txtBHYT.Text;
            tbl.Birthday = txtBirthday.Text;
            tbl.CMND = txtCMND.Text;
            tbl.FirstName = txtFirstName.Text;
            tbl.LastName = txtLastName.Text;
            tbl.MaritalStatus = cbbMaritalStatus.Text;
            tbl.Sex = cbbSex.Text;
            tbl.Tel = txtTel.Text;
            tbl.DateRegistered = DateTime.Now.ToShortDateString();
            if (bnbuo.Insert(tbl))
            {
                lbThongBao.Text = "Thêm thành công";
                
            }
            else
            {
                lbThongBao.Text = "Thêm thất bại";
                
            }
            showData();
        }
        /// <summary>
        /// Thêm thông tin người nhà cho bệnh nhân
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void thânNhânToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ucThemNguoiNha nguoiNha = new ucThemNguoiNha(int.Parse(ID_Co));
            ControlAcess.ShowConTrol(this.ParentForm,nguoiNha,"gbHienThi");
        }

        private void đăngKýKhámToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Hiển thị form khám bệnh
            ucDangKyKham dk = new ucDangKyKham(ID_Co);
            ControlAcess.ShowConTrol(this.ParentForm, dk, "gbHienThi");
        }
        /// <summary>
        /// Lấy id bệnh nhân
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    DataGridView.HitTestInfo hit = dataGridView1.HitTest(e.X, e.Y);


                    // Only RowHeader and Cells (which make up a row) should fire a menu
                    if (hit.Type == DataGridViewHitTestType.RowHeader
                        || hit.Type == DataGridViewHitTestType.Cell
                        && hit.RowIndex >= 0)
                    {
                        // Notice how I assign the menu to the dataGridView below...

                        dataGridView1.ClearSelection();
                        dataGridView1.Rows[hit.RowIndex].Selected = true;
                        dataGridView1.ContextMenuStrip = contextMenuStrip1;
                        dataGridView1.ContextMenuStrip.Show(this.dataGridView1, new Point(e.X, e.Y));


                        ID_Co = dataGridView1.Rows[hit.RowIndex].Cells[0].Value.ToString();

                    }
                    // and then I remove the menu here...
                    // This is because after we assign it to the dataGridView
                    // it allows you to right-click anywhere on the control to
                    // get a menu.  Try removing this line and expirement.
                    dataGridView1.ContextMenuStrip = null;

                }
            }
            catch
            {
                contextMenuStrip1.Visible = false;
            }
        }
        /// <summary>
        /// Xem lịch sửa khám của bệnh nhân
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lịchSửaKhámToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ucLichSuKham ls = new ucLichSuKham(int.Parse(ID_Co));
            ControlAcess.ShowConTrol(this.ParentForm, ls, "gbHienThi");
        }

        
        private void button1_Click(object sender, EventArgs e)
        {
            
        }

    }
}
